package com.hxd.otc.module.wallet.presenter;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.wallet.activity.CoinRecordActivity;
import com.hxd.otc.module.wallet.bean.WalletCoinRecordBean;
import com.hxd.otc.module.wallet.contract.WalletCoinRecordContract;
import com.hxd.otc.module.wallet.model.WalletModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * 包  名 :  com.hxd.otc.mvp.wallet
 * 类  名 :  CoinRecordPresenter
 * 作  者 :  卫广玉
 * 时  间 :  2018/6/5 17:32
 * 描  述 :  钱包记录
 */
public class CoinRecordPresenter extends BasePresenter<WalletCoinRecordContract.View> implements WalletCoinRecordContract.Presenter {

    private final WalletModel mModel;

    public CoinRecordPresenter(WalletCoinRecordContract.View view) {
        super(view);
        mModel = WalletModel.getInstance();
    }


    @Override
    public void getWalletCoinRecord(final int flag, long page, long size) {
        mModel.getWalletCoinRecord(new BaseObserver<WalletCoinRecordBean>() {
            @Override
            public void onNext(String title, WalletCoinRecordBean beans) {
                if (flag == CoinRecordActivity.REFRESH) {
                    mView.finishRefresh();
                    mView.refreshData(beans.list);
                } else if (flag == CoinRecordActivity.LOADMORE) {
                    mView.finishLoadMore();
                    mView.loadMoreData(beans.list);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                if (flag == CoinRecordActivity.REFRESH) {
                    mView.finishRefresh();
                } else if (flag == CoinRecordActivity.LOADMORE) {
                    mView.finishLoadMore();
                }
                mView.showToast(errMessage);
                mView.onError(errType);

            }

        }, mView.<BaseBean<WalletCoinRecordBean>>bindAutoDispose(), page, size);
    }


}